#include "battery.h"

uint32_t battery_voltage_raw = 0;

void battery_init(void)
{
    HAL_ADC_EnableDMA(ADC_FOR_BATTERY, &battery_voltage_raw, 1);
}

float battery_voltage(void)
{
    float voltage = (float)battery_voltage_raw/4096*3.3f*2;
    return voltage;
}

void battery_charge(uint8_t opt)
{
    HAL_GPIO_WritePin(BATTERY_CHG_Port, BATTERY_CHG_GPIO_Pin, opt==0);
}

uint8_t battery_is_charge(void)
{
    return HAL_GPIO_ReadPin(BATTERY_CHG_Port, BATTERY_CHG_GPIO_Pin)==0;
}